home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Samples / SampleCode / Plug-in - WireFrame Renderer / SR_PixmapMarker.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  7.0 KB  |  255 lines  |  [TEXT/MPS ]

  1. /******************************************************************************
  2.  **                                                                             **
  3.  **     Module:        SR_PixmapMarker.c                                         **
  4.  **                                                                          **
  5.  **                                                                          **
  6.  **     Purpose:     This is the entry point into SR for pixmap markers.          **
  7.  **                                                                          **
  8.  **                                                                          **
  9.  **                                                                          **
  10.  **     Copyright (C) 1996 Apple Computer, Inc.  All rights reserved.          **
  11.  **                                                                          **
  12.  **                                                                          **
  13.  *****************************************************************************/
  14. #include <assert.h>
  15. #include <stdlib.h>
  16.  
  17. #include "QD3D.h"
  18. #include "QD3DMath.h"
  19.  
  20. #include "SR.h"
  21. #include "SR_Marker.h"
  22. #include "QD3DShader.h"
  23.  
  24.  
  25. /*===========================================================================*\
  26.  *
  27.  *    Routine    :    SR_Geometry_PixmapMarker()
  28.  *
  29.  *    Comment    :    This function is the pixmapMarker renderer entry point, it 
  30.  *                collects the state of escher, updates the state of the world
  31.  *                and then calls the appropiate rendering function.
  32.  *
  33. \*===========================================================================*/
  34.  
  35. TQ3Status SR_Geometry_PixmapMarker(
  36.     TQ3ViewObject                 view, 
  37.     TSRPrivate                     *srPrivate,
  38.     TQ3GeometryObject             pixmapMarker,
  39.     const TQ3PixmapMarkerData    *pixmapMarkerData)
  40. {
  41.     TQ3Boolean                highlightState;
  42.     TQ3ColorRGB                highlightColor;
  43.     TQ3XClipMaskState        clipMaskState;
  44.     
  45.     UNUSED(pixmapMarker);
  46.  
  47.     assert(view             != NULL);
  48.     assert(srPrivate         != NULL);
  49.     assert(pixmapMarkerData != NULL);
  50.     
  51.     /*
  52.      *  Call the application's idle progress method, via the view.  If
  53.      *  the app's method returns kQ3Failure, then we don't go on.
  54.      */
  55.     if (SR_IdleProgress(view, srPrivate) == kQ3Failure) {
  56.         return (kQ3Success);
  57.     }
  58.  
  59.     if (srPrivate->drawRegion == NULL) {
  60.         return (kQ3Success);
  61.     }
  62.  
  63.     /*
  64.      *  Find out if we're clipped out or not. No reason to go any
  65.      *  further if the region is obscured or entirely off-screen. 
  66.      */
  67.     Q3XDrawRegion_GetClipFlags(srPrivate->drawRegion, &clipMaskState);
  68.     if (clipMaskState == kQ3XClipMaskNotExposed) {
  69.         return (kQ3Success);
  70.     }
  71.  
  72.     /*
  73.      *  Lazy-evaluate the various transforms for the pipeline
  74.      */
  75.     if (SR_UpdatePipeline(srPrivate) == kQ3Failure) {
  76.         return (kQ3Failure);
  77.     }
  78.  
  79.  
  80.     /*
  81.      *  Highlight state and  color are from the view, unless
  82.      *  overridden by the lineAttributeSet
  83.      */
  84.     Q3ColorRGB_Set(&highlightColor, kQ3ViewDefaultHighlightColor);
  85.     
  86.     /*
  87.      *  Get highlight state from the current view state
  88.      */
  89.     highlightState = srPrivate->viewHighlightState;
  90.     
  91.     /*
  92.      *  Check for highlight state in the pixmap marker itself
  93.      */
  94.     if (pixmapMarkerData->pixmapMarkerAttributeSet != NULL) {
  95.         TQ3XAttributeMask    attributeMask;
  96.         
  97.         attributeMask = Q3XAttributeSet_GetMask(
  98.                             pixmapMarkerData->pixmapMarkerAttributeSet);
  99.  
  100.         if (attributeMask & kQ3XAttributeMaskHighlightState) {
  101.             Q3AttributeSet_Get(
  102.                 pixmapMarkerData->pixmapMarkerAttributeSet, 
  103.                 kQ3AttributeTypeHighlightState, 
  104.                 &highlightState);
  105.         }
  106.     }
  107.  
  108.  
  109.     /*
  110.      *  If highlight state is true, and there's a view hightlight attribute set, and if 
  111.      *  there's a color in there, use that as the highlight color.
  112.      */
  113.     if ((highlightState == kQ3True) &&
  114.         (srPrivate->viewHighlightAttributeSet != NULL)) {
  115.         TQ3XAttributeMask    attributeMask;
  116.         
  117.         attributeMask = Q3XAttributeSet_GetMask(
  118.                             srPrivate->viewHighlightAttributeSet);
  119.                             
  120.         if (attributeMask & kQ3XAttributeMaskDiffuseColor) {
  121.             Q3AttributeSet_Get( 
  122.                 srPrivate->viewHighlightAttributeSet, 
  123.                 kQ3AttributeTypeDiffuseColor, 
  124.                 &highlightColor);
  125.         }
  126.     }
  127.     
  128.     
  129.     {
  130.         TQ3Matrix4x4                *localToDC;
  131.         TQ3RationalPoint4D            *deviceVertices = NULL;
  132.         TQ3RationalPoint4D            *renderVertices = NULL;
  133.         PixmapMarkerFunction2D        pixmapMarkerFunc;
  134.         TSRPixmapMarkerRasterData    rasterPixmapMarker;
  135.         TQ3Point2D                    saveDeviceVertices;
  136.  
  137.         /*        
  138.          *  1.0     transform local coordinate vertices to DC
  139.          *    1.5        add in offsets
  140.          *  2.0        clip in DC
  141.          *  3.0     paste bitmap
  142.          */
  143.         TQ3StoragePixmap    *pixmapPtr = (TQ3StoragePixmap *)
  144.                                             &(pixmapMarkerData->pixmap);
  145.         float                inverseW;
  146.         
  147.         localToDC = &srPrivate->transforms.localToDC;
  148.  
  149.         deviceVertices = malloc(sizeof(TQ3RationalPoint4D));
  150.         if (deviceVertices == NULL) {
  151.             return (kQ3Failure);
  152.         }
  153.  
  154.         /* 1. transform LC to DC */
  155.         Q3Point3D_To4DTransformArray(&pixmapMarkerData->position, 
  156.                                      localToDC,
  157.                                      deviceVertices, 
  158.                                      1,
  159.                                      sizeof(TQ3Point3D), 
  160.                                      sizeof(TQ3RationalPoint4D));
  161.                                      
  162.         inverseW = 1.0 / deviceVertices->w;
  163.         deviceVertices->x *= inverseW;
  164.         deviceVertices->y *= inverseW;
  165.         deviceVertices->z *= inverseW;
  166.  
  167.         deviceVertices->x += pixmapMarkerData->xOffset;
  168.         deviceVertices->y += pixmapMarkerData->yOffset;
  169.         
  170.         deviceVertices->x = FLOAT_ROUND_TO_LONG_POSITIVE(
  171.                                 deviceVertices->x);
  172.         deviceVertices->y = FLOAT_ROUND_TO_LONG_POSITIVE(
  173.                                 deviceVertices->y);
  174.         
  175.         /* Check for trivial rejection clipping */
  176.         
  177.         if (deviceVertices->z < srPrivate->clipPlanesInDC[4]     || 
  178.             deviceVertices->z > srPrivate->clipPlanesInDC[5]     ||
  179.             deviceVertices->x + pixmapPtr->width - 1 < 
  180.                 srPrivate->clipPlanesInDC[0]                     ||
  181.             deviceVertices->x > srPrivate->clipPlanesInDC[1]     ||
  182.             deviceVertices->y + pixmapPtr->height - 1 < 
  183.                 srPrivate->clipPlanesInDC[2]                    ||
  184.             deviceVertices->y > srPrivate->clipPlanesInDC[3]) {
  185.             /* trivial rejection */
  186.             return (kQ3Success);
  187.         }
  188.  
  189.         /* 
  190.          *  PixmapMarker dimensions could be bigger than window 
  191.          *  so clip against all boundaries 
  192.          */
  193.         rasterPixmapMarker.pixmap = pixmapPtr;
  194.  
  195.         rasterPixmapMarker.startRowSkip = 0;
  196.         rasterPixmapMarker.endRowSkip = 0;
  197.  
  198.         saveDeviceVertices.x = deviceVertices->x;
  199.         saveDeviceVertices.y = deviceVertices->y;
  200.         
  201.         if (deviceVertices->x < srPrivate->clipPlanesInDC[0]) {
  202.             rasterPixmapMarker.startRowSkip = 
  203.                 srPrivate->clipPlanesInDC[0] - deviceVertices->x;
  204.             deviceVertices->x = srPrivate->clipPlanesInDC[0];
  205.         }
  206.         
  207.         if (saveDeviceVertices.x + pixmapPtr->width - 1 > 
  208.                 srPrivate->clipPlanesInDC[1]) {
  209.             rasterPixmapMarker.endRowSkip = 
  210.                 saveDeviceVertices.x + pixmapPtr->width - 1 
  211.                                       - srPrivate->clipPlanesInDC[1];
  212.         }
  213.         
  214.         rasterPixmapMarker.startLineSkip = 0;
  215.         rasterPixmapMarker.endLineSkip = 0;
  216.         
  217.         if (deviceVertices->y < srPrivate->clipPlanesInDC[2]) {
  218.             rasterPixmapMarker.startLineSkip = 
  219.                 srPrivate->clipPlanesInDC[2] - deviceVertices->y;
  220.             deviceVertices->y = srPrivate->clipPlanesInDC[2];
  221.         }
  222.         
  223.         if (saveDeviceVertices.y + pixmapPtr->height - 1 > 
  224.                 srPrivate->clipPlanesInDC[3]) {
  225.             rasterPixmapMarker.endLineSkip = 
  226.                 saveDeviceVertices.y + pixmapPtr->height - 1 
  227.                                        - srPrivate->clipPlanesInDC[3];
  228.         }
  229.         
  230.         /*
  231.          *  Call the appropriate pixmap marker rasterizer.
  232.          */
  233.         pixmapMarkerFunc = ((TSRRasterFunctions *)
  234.             (srPrivate->currentRasterFunctions))->pixmapMarkerFunction;
  235.  
  236.         if ((*pixmapMarkerFunc)(
  237.                 srPrivate, 
  238.                 (TQ3Point3D *) deviceVertices, 
  239.                 &rasterPixmapMarker,
  240.                 highlightState == kQ3True ? &highlightColor : NULL) == kQ3Failure) {
  241.             if (deviceVertices != NULL) {
  242.                 free(deviceVertices);
  243.             }
  244.             
  245.             return (kQ3Failure);
  246.         }
  247.     
  248.         if (deviceVertices != NULL) {
  249.             free(deviceVertices);
  250.         }
  251.     }
  252.     
  253.     return (kQ3Success);
  254. }
  255.